//
//  EPMSearchViewController.m
//  myXianfeng
//
//  Created by 马继鵬 on 17/5/6.
//  Copyright © 2017年 EPM. All rights reserved.
//

#import "EPMSearchViewController.h"
#define Search  (@"\U0000e505")
@interface EPMSearchViewController ()
@property (weak,nonatomic)  UILabel* searchLab;
@property (weak,nonatomic)  UITextField* searchField;
@end

@implementation EPMSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor lightGrayColor];
    [self setupUI];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    
}

#pragma mark - 设置UI -

- (void)setupUI{
    [self setTitleView];
}

#pragma mark - 设置titleView -

- (void)setTitleView{
    UIView* titleView = [[UIView alloc]init];
    titleView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:titleView];
    
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self.view);
        make.height.mas_equalTo(64);
    }];
    
//    设置Btn
    UIButton* searchBtn = [[UIButton alloc]init];
    [titleView addSubview:searchBtn];
    searchBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
    searchBtn.backgroundColor = lightBackColor;
    [searchBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [searchBtn.titleLabel setFont:[UIFont fontWithName:@"iconfont" size:15]];
    [searchBtn setTitle:[NSString stringWithFormat:@"%@ 请输入商品名称",Search] forState:UIControlStateNormal];
    searchBtn.layer.masksToBounds = YES;
    searchBtn.layer.cornerRadius = 5;
    
    [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(titleView).offset(20);
        make.centerY.equalTo(titleView).offset(15);
        make.width.equalTo(titleView).multipliedBy(0.8);
        make.height.mas_equalTo(30);
    }];
    
    UILabel* searchLabel = [[UILabel alloc]init];
    [titleView addSubview:searchLabel];
    self.searchLab = searchLabel;
    searchLabel.backgroundColor = lightBackColor;
    searchLabel.hidden = YES;
    searchLabel.text = [NSString stringWithFormat:@"%@",Search];
    searchLabel.font = [UIFont fontWithName:@"iconfont" size:15];
    searchLabel.textColor = [UIColor grayColor];
    searchLabel.textAlignment = NSTextAlignmentCenter;
    [searchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(titleView).offset(20);
        make.centerY.equalTo(titleView).offset(15);
        make.height.width.mas_equalTo(30);
    }];

    
    UITextField* textField = [[UITextField alloc]init];
    [titleView addSubview:textField];
    textField.textColor = [UIColor grayColor];
    [textField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
    [textField setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];
    
    textField.placeholder = @"请输入商品名称";
    textField.backgroundColor = lightBackColor;
    textField.hidden =YES;
    self.searchField = textField;
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(searchLabel.mas_trailing);
        make.height.centerY.equalTo(searchLabel);
        make.trailing.equalTo(titleView).offset(- 0.2 * ScreenWidth);
    }];
    
    
    UIButton* cancelBtn = [[UIButton alloc]init];
    [titleView addSubview:cancelBtn];
    
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:appColor forState:UIControlStateNormal];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(titleView).offset(15);
        make.trailing.equalTo(titleView).offset(-20);
    }];
    
    [searchBtn addTarget:self action:@selector(actionSearchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [cancelBtn addTarget:self action:@selector(actionCancelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
}
#pragma mark - titleView点击事件 -

- (void)actionCancelBtnClick:(UIButton*)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)actionSearchBtnClick:(UIButton*)sender{
    sender.hidden = YES;
    self.searchField.hidden = NO;
    self.searchLab.hidden = NO;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
